# Contributor: Thomas Dziedzic <gostrc@gmail.com>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: John Proctor <jproctor@prium.net>
# Contributor: Jeramy Rutley <jrutley@gmail.com>

pkgname=ruby2.7
pkgver=2.7.8
pkgrel=1
arch=(loong64 x86_64)
pkgdesc='An object-oriented language for quick and easy programming, version 2.7'
url='https://www.ruby-lang.org/en/'
license=(BSD custom)
depends=(libxcrypt gdbm openssl libffi libyaml gmp zlib)
optdepends=(
    'tk: for Ruby/TK'
)
makedepends=(tk)
options=(!emptydirs !lto) # Disable LTO until fixes for https://bugs.ruby-lang.org/issues/18062 released
_osslver=3.0.0
source=(https://cache.ruby-lang.org/pub/ruby/${pkgver:0:3}/ruby-${pkgver}.tar.xz
        ruby2.7-do-not-depend-on-ext-openssl-deprecation-rb.patch::https://github.com/ruby/ruby/commit/28f3e038805a4f396f228c6884c531677c075867.patch
        ruby-openssl-$_osslver.tar.xz::https://github.com/ruby/openssl/archive/refs/tags/v$_osslver.tar.gz)
sha512sums=('4b49dff3e1c2e79d914e10418e4c03026f5d4c137dc337f5c720fe26cb9fcdcf4afc6b7c967356cf5fbe04cc5ef431174c48a035becf3e2322c2c45d3c9b2f59'
            '914dec716bbc9d0e7c7e7f76e599fc545f4adcc7f84a16c31e6b8badc3556dfa1c21c4a5fe1d04cf3fc2d3930cc769c34f4b5f638404f7c023bffdb49a33bef0'
            '076d2924b61c4f7704b47718a33732fb5285a3af39f328ed9e83add36589da99dfae73b3e893398fc3f2a74dcbead0b66edc682040fa1b48f9530894c7187f95')

prepare() {
  cd ruby-${pkgver}
  patch -Np1 -i ../ruby2.7-do-not-depend-on-ext-openssl-deprecation-rb.patch
  rm -rf ext/openssl test/openssl
  mv ../openssl-$_osslver/ext/openssl ext
  mv ../openssl-$_osslver/lib ext/openssl
  mv ../openssl-$_osslver/{History.md,openssl.gemspec} ext/openssl
  mv ../openssl-$_osslver/test/openssl test
}

build() {
  cd ruby-${pkgver}

  ./configure \
    --prefix=/usr \
    --program-suffix=-2.7 \
    --with-soname=ruby-2.7 \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sharedstatedir=/var/lib \
    --libexecdir=/usr/lib/ruby \
    --enable-shared \
    --disable-rpath \
    --with-dbm-type=gdbm_compat \
    --disable-install-doc

  make
}

package() {
  cd ruby-${pkgver}

  make DESTDIR="${pkgdir}" install-nodoc

  install -D -m644 COPYING "${pkgdir}/usr/share/licenses/ruby2.7/LICENSE"
  install -D -m644 BSDL "${pkgdir}/usr/share/licenses/ruby2.7/BSDL"

  # remove files conflicting with 'ruby' package
  rm -r "$pkgdir"/usr/share/man/
}
